#include "EEventManager.h"
#include "EPhScene.h"

#include "eCPP.h"
namespace engine
{

//------------------------------------------------------------
// EEventManager
//------------------------------------------------------------
EEventManager::EEventManager() :
m_pPhScene( NULL )
{

}

//------------------------------------------------------------
EEventManager::~EEventManager()
{
  /*for( vector<EEventShape*>::iterator it = m_vecShapes.begin(); 
    it != m_vecShapes.end(); ++it )
  {
    delete (*it);
  }*/
  m_vecShapes.clear();
}

//------------------------------------------------------------
void EEventManager::addEventShape(engine::EEventShape& shape)
{
  m_vecShapes.push_back( &shape );
}

//------------------------------------------------------------
void EEventManager::removeEventShape(EEventShape& shape)
{
  for( vector<EEventShape*>::iterator it = m_vecShapes.begin();
    it != m_vecShapes.end(); ++it )
  {
    if( *it == &shape )
      m_vecShapes.erase( it );
  }
}

//------------------------------------------------------------
bool EEventManager::startGame(EPhScene& phScene)
{
  m_pPhScene = &phScene;
  cASSERT( m_pPhScene != NULL );
  for( EEventShapeVector::iterator it = m_vecShapes.begin(); it != m_vecShapes.end(); ++it )
  {
    (*it)->createActor( *m_pPhScene );
  }
  return true;
}

//------------------------------------------------------------
bool EEventManager::updateGame(const EGameTime& time )
{
  for( EEventShapeVector::iterator it = m_vecShapes.begin(); it != m_vecShapes.end(); ++it )
  {
  }
  return true;
}

//------------------------------------------------------------
bool EEventManager::endGame()
{
  cASSERT( m_pPhScene != NULL );
  for( EEventShapeVector::iterator it = m_vecShapes.begin(); it != m_vecShapes.end(); ++it )
  {
    (*it)->destroyActor( *m_pPhScene );
  }
  return true;
}

} // end namespace